home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / ReadOLM / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  5KB  |  230 lines

  1. /* **** HBBS Door Code****************************************************** */
  2.  
  3. /*
  4.   DoorName
  5.   ========
  6.  
  7.     what the door does
  8.  
  9.   Version
  10.   =======
  11.  
  12.     x.xx, release xx, dd/mm/yyyy
  13.  
  14.   Options
  15.   =======
  16.  
  17.     N_ND->ActiveDoor->SystemOptions
  18.     -------------------------------
  19.  
  20.  
  21.  
  22.     Command Line Arguments
  23.     ----------------------
  24.  
  25.     2  <option>
  26.  
  27.     3  ...
  28.  
  29.     4  .
  30.  
  31.   ToDo
  32.   ====
  33.  
  34.     what you still have to do
  35.  
  36.  
  37.  
  38. */
  39.  
  40. /* **** Includes *********************************************************** */
  41.  
  42. #include <exec/types.h>
  43. #include <exec/memory.h>
  44. #include <dos/dos.h>
  45. #include <clib/exec_protos.h>
  46. #include <clib/dos_protos.h>
  47. #include <clib/alib_protos.h>
  48.  
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <stdio.h>
  52. #include <ctype.h>
  53. #include <time.h>
  54.  
  55. #include <HBBS/ANSI_Codes.h>
  56. #include <HBBS/Defines.h>
  57. #include <HBBS/Access.h>
  58. #include <HBBS/types.h>
  59. #include <HBBS/structures.h>
  60. #include <HBBS/hbbscommon_protos.h>
  61. #include <HBBS/hbbscommon_pragmas.h>
  62. #include <HBBS/Hbbsnode_protos.h>
  63. #include <HBBS/Hbbsnode_pragmas.h>
  64. #include <HBBS/release.h>
  65. char *versionstr="$VER: ReadOLM "RELEASE_STR;
  66.  
  67. /* **** Variables ********************************************************** */
  68.  
  69.  
  70. struct Library *HBBSCommonBase  = NULL;
  71. struct Library *HBBSNodeBase    = NULL;
  72.  
  73. struct BBSGlobalData *BBSGlobal = NULL;
  74. struct NodeData *N_ND           = NULL;
  75. int    N_NodeNum                = -1;
  76. char   outstr[2048];
  77.  
  78. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  79.                       // random/suprious crashings after or during the running
  80.                       // of your door.
  81.  
  82. int    gargc;         // these are just copies of main()'s argc and argv..
  83. char   **gargv;
  84.  
  85. /* **** Functions ********************************************************** */
  86.  
  87.  
  88. #ifdef __SASC
  89. int CXBRK(void) { return(0); }
  90. int _CXBRK(void) { return(0); }
  91. void chkabort(void) {}
  92. #endif
  93.  
  94. static VOID cleanup(ULONG num)
  95. {
  96.   if (HBBSNodeBase)
  97.   {
  98.     HBBS_CleanUpDoor();
  99.     CloseLibrary (HBBSNodeBase);
  100.   }
  101.  
  102.   if (HBBSCommonBase)
  103.   {
  104.     HBBS_CleanUpCommon();
  105.     CloseLibrary (HBBSCommonBase);
  106.   }
  107.  
  108.   if (num) printf("Door Error = %d\n",num);
  109.  
  110.   exit(0);
  111. }
  112.  
  113. static VOID init(char *name)
  114. {
  115.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  116.   {
  117.     cleanup(1);
  118.   }
  119.  
  120.   if (!(HBBS_InitCommon()))
  121.   {
  122.     cleanup(2);
  123.   }
  124.  
  125.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  126.   {
  127.     cleanup(3);
  128.   }
  129.  
  130.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  131.   {
  132.     cleanup(4);
  133.   }
  134.   SetProgramName(name);
  135. }
  136.  
  137. /* **** DoorMain *********************************************************** */
  138.  
  139. void DoorMain( void )
  140. {
  141.   BOOL error=FALSE;
  142.   struct OLMNode *OLM;
  143.  
  144.   char oldcharsallowed[BIG_STR];
  145.  
  146.   strcpy(oldcharsallowed,N_ND->CharsAllowed);
  147.   N_ND->NodeFlags+=NFLG_HANDLINGOLM; // *C* check it's not already set!
  148.  
  149.   while (N_ND->OLMCount && N_ND->OnlineStatus==OS_ONLINE && !error)
  150.   {
  151.     if (OLM = (struct OLMNode*)N_ND->OLMList->lh_Head)
  152.     {
  153.       sprintf(outstr,ANSI_RESET ANSI_FG_WHITE "\r\nOLM Received! %s %s%s%s\r\n",OLM->Time,OLM->Date,OLM->FromPRG[0] ? " Created By: " : "",OLM->FromPRG);
  154.  
  155.       if (OLM->Handle[0])
  156.       {
  157.         sprintf(outstr+strlen(outstr),ANSI_FG_CYAN "From "ANSI_FG_BLUE": "ANSI_FG_WHITE "%s, ",OLM->Handle);
  158.       }
  159.  
  160.       sprintf(outstr+strlen(outstr),ANSI_FG_CYAN "Message "ANSI_FG_BLUE": "ANSI_FG_WHITE "%s\r\n",OLM->node.ln_Name);
  161.       DOOR_WriteText(outstr);
  162.  
  163.       if (OLM->FromNode)
  164.       {
  165.         if (DOOR_ContinuePrompt("Reply to the OLM ? ",DEFAULT_NO|DCP_ADDYN))
  166.         {
  167.           DOOR_WriteText(ANSI_FG_YELLOW "Enter a reply "ANSI_FG_BLUE "> "ANSI_FG_WHITE);
  168.           DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_NOOLM,'\0',0,0,NULL);
  169.           RemoveSpaces(N_ND->CurrentLine);
  170.           if (N_ND->OnlineStatus==OS_ONLINE)
  171.           {
  172.             if (N_ND->CurrentLine[0])
  173.             {
  174.               if (HBBS_SendOLM(N_ND->NodeNum+1,"ReplyOLM",OLM->FromNode-1,N_ND->CurrentLine,0))
  175.               {
  176.                 DOOR_WriteText("Reply Sent!\r\n");
  177.               }
  178.               else
  179.               {
  180.                 DOOR_WriteText("Reply Failed, node may be busy, offline or user has logged off!\r\n");
  181.               }
  182.             }
  183.           } else error=TRUE; //lost carrier!
  184.         }
  185.       }
  186.       else
  187.       {
  188.         DOOR_PausePrompt(NULL);
  189.       }
  190.  
  191.       HBBS_FreeNode((struct Node*)OLM,TRUE); //free and remove()
  192.       N_ND->OLMCount--;
  193.     }
  194.     else error=TRUE;
  195.   }
  196.   if (!N_ND->OLMCount)
  197.   {
  198.     if (N_ND->NodeFlags & NFLG_OLMSWAITING) N_ND->NodeFlags-=NFLG_OLMSWAITING;
  199.   }
  200.  
  201.   N_ND->NodeFlags-=NFLG_HANDLINGOLM; // *C* check it's set!
  202.  
  203.   strcpy(N_ND->CharsAllowed,oldcharsallowed);
  204.  
  205. }
  206.  
  207. int main(int argc,char **argv)
  208. {
  209.   gargc=argc;
  210.   gargv=argv;
  211.  
  212.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  213.   {
  214.     printf("Invalid/No Paramaters for door!\n");
  215.     exit (20);
  216.   }
  217.   init("ReadingOLMs");
  218.  
  219.   if (BBSGlobal=HBBS_GimmeBBS())
  220.   {
  221.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  222.     {
  223.       DoorMain();
  224.     }
  225.   }
  226.   cleanup(0);
  227. }
  228.  
  229. /* **** End Of File ******************************************************** */
  230.